<?php 
include_once 'CF_TableEdPage.php';

class CF_TableEdInline extends CF_TableEdPage {
	

	var $keys_hidden; // keys as hidden fields in form
	var $actionpage; // page form will go to for edit and delete actions
	var $ordervar = 'order';  // set this variable for order when re-ording this query with the headers
	var $oldvalvar = 'OV_';  // This is the prefix for original value in a form

	var $allow_save = true;
	
    var $mode_save = 'Save';
    var $mode_delete = 'Delete';
    var $mode_duplicate = 'Copy';
	var $mode_edit = 'Edit';


	// New Methods
	function set_actionpage($pagename){
		$this->actionpage = $pagename;
	}	

	
	function clear_keys_strings() { 
		$this->keys_uid = '';
		$this->keys_hidden = '';
		parent::clear_keys_strings();
	}
	
	function make_lookup_value($column,$value){
        $showkey = 'showvalue';
        $valuekey = 'keyvalue';
    	$valuesarray = $this->fieldspec[$column]['list'];
        if(isset($this->fieldspec[$column]['showvalue'])){
            $showkey = $this->fieldspec[$column]['showvalue'];
        }
        if(isset($this->fieldspec[$column]['keyvalue'])){
            $valuekey = $this->fieldspec[$column]['keyvalue'];
        }

        foreach ($valuesarray as $lookup_pair) {
            if($lookup_pair[$valuekey] == $value){
                return $lookup_pair[$showkey];
            }
         }
         return $value;

    }
	
	function make_rowval($value,$column){
		
		$row_text .= "<td>";
        $row_text .= $this->make_valuebox($value,$column);
		$row_text .= "</td>";
		return $row_text;
			
	}

   function make_valuebox($value,$column){
      	if($this->fieldspec[$column]['show'] == 'E'){
            $chgname = "validateData" . "('$column', '$this->keys_uid', '$column" . "_" . "$this->keys_uid')";
            $row_text .= MakeEditField($this->fieldspec[$column],$column,$value,$chgname,$column . '_' . $this->keys_uid,false,$this->top_dir);
			$ov_name = $this->oldvalvar . $column;
			$row_text .= "<input type='hidden' name='$ov_name' value='$value' id='$ov_name" . "_$this->keys_uid'>";
		}  else if($this->fieldspec[$column]['show'] == 'L') {
            $row_text .= $this->make_lookup_value($column,$value);
        }else {
            $row_text .= "$value";
		}
		return $row_text;
    }


 /**
 * function to make start of row, making each row a form for editing
 * @param int $row_num This is the row number of the dataset
 * @param string $key_string This is the string of key values, defined by make_key_string function
 * @return string Row begining 
 */
	function make_row_start($row_num){
		$formname = $this->tablename . '_' . $this->keys_uid;
		$rowstart .= "<form action='$this->actionpage' name='$formname' method='GET'>";

		$rowstart .= $this->keys_hidden;
		
		if($this->row_status == 'even'){
			$this->row_status = 'odd';
			$rowstart .= "<tr class=\"$this->table_even_class\">";			
		}
		else{
			$this->row_status = 'even';
			$rowstart .= "<tr class=\"$this->table_odd_class\">";			
		}

		return $rowstart;
	}


	function make_row_end($row_num){
		if($this->allow_save){
			$rowend .= "<td class='actsave'><input type='submit' name='mode' value='" . $this->mode_save . "'></td>";
		}
		$rowend .= "</tr></form>\n";
		
		return $rowend;
	}
	
}// end Class CF_InlineEDTable

?>